/*
 * BanBu_VideoAuthenViewController
 * @description 本文件提供视频认证界面的ViewVontroller
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供视频认证界面的ViewVontroller
 */

#import "BanBu_VideoAuthenViewController.h"
#import "UIViewController+Animation.h"
#import "BanBu_VideoVerifyViewController.h"
#import "BanBu_AvatarSelectViewController.h"
#import "AppCommunicationManager.h"
#import "BanBu_LocationManager.h"
#import "AppDataManager.h"
#import "UIButton+WebCache.h"
@interface BanBu_VideoAuthenViewController ()

@end

@implementation BanBu_VideoAuthenViewController
-(void)viewWillAppear:(BOOL)animated
{
    [UIView setAnimationsEnabled:YES];
    [super viewWillAppear:animated];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(id)initWithRegisterVerify:(BOOL)_flag
{
    self = [super init];
    if(self)
    {
        isRegisterVerify = _flag;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    if(isRegisterVerify)
    {
        UIButton *returnBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        returnBtn.frame=CGRectMake(0, 0, 60, 30);
        
        [returnBtn setTitle:@"" forState:UIControlStateNormal];
        returnBtn.hidden=YES;
        UIBarButtonItem *returnItem = [[[UIBarButtonItem alloc] initWithCustomView:returnBtn] autorelease];
        
        self.navigationItem.leftBarButtonItem = returnItem;
    }
    
    self.title = NSLocalizedString(@"videoVerify", nil);
    passVerifyInfiveMinute.frame = CGRectMake(0, __MainScreen_Height-235-44, passVerifyInfiveMinute.frame.size.width, passVerifyInfiveMinute.frame.size.height);
    [startVerify setTitle:NSLocalizedString(@"wantVerify", nil) forState:UIControlStateNormal];
    noticeLabel.text = NSLocalizedString(@"videoHelpText", nil);
    
    //修改2014年08月06日11:25:36，添加视频认证注意
    [noticeLabel sizeToFit];
    _noteLabel.text = NSLocalizedString(@"video_authentication_notice", nil);
    [_noteLabel sizeToFit];
    _noteLabel.frame = CGRectMake(40, 12 + noticeLabel.frame.size.height, 250, _noteLabel.frame.size.height);
    [startVerify setFrame:CGRectMake(35, 18 + noticeLabel.frame.size.height + _noteLabel.frame.size.height, 250, 46)];
    //修改完成2014年08月06日11:35:57
    
    [passedNotice setTitle:NSLocalizedString(@"passVerifyUserNotice", nibBundleOrNil) forState:UIControlStateNormal];
    
    
    NSDictionary *parDic = [NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:@"%f",AppLocationManager.curLocation.latitude*1000000],@"plat", [NSString stringWithFormat:@"%f",AppLocationManager.curLocation.longitude*1000000],@"plong",nil];
    [AppComManager getBanBuData:BanBu_Get_Video_Verify par:parDic delegate:self];
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
-(void)startVerify:(id)sender
{
    BanBu_AvatarSelectViewController *reg = [[BanBu_AvatarSelectViewController  alloc] initWithRegisterVerify:isRegisterVerify];
    [self.navigationController pushViewController:reg animated:YES];
    [reg release];
}
- (void)banbuRequestDidFinished:(NSDictionary *)resDic error:(NSError *)error
{
    
    if(error)
    {
        
    }
    else
    {
        if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_Video_Verify])
        {
            if([[resDic valueForKey:@"ok"] boolValue])
            {
//                NSLog(@"%d",[[resDic valueForKey:@"list"] count]>=8?8:[[resDic valueForKey:@"list"] count]);
                NSInteger num = [[resDic valueForKey:@"list"] count]>=8?8:[[resDic valueForKey:@"list"] count];
                for(int i = 0;i < num;i ++)
                {
                    NSDictionary *vipUser = [[resDic valueForKey:@"list"] objectAtIndex:i];
                    UIButton *btn = (UIButton *)[passVerifyInfiveMinute viewWithTag:(i+1)*100];
                    [btn setImageWithURL:[NSURL URLWithString:[vipUser valueForKey:@"uface"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:0];
                    


                    
                    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, 65, 15)];
                    bottomView.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.8];
                    [btn addSubview:bottomView];
                    [bottomView release];

                    UIImageView *_sexImgV = [[UIImageView alloc]initWithFrame:CGRectMake(33, 2, 13, 13)];
                    NSString *sexpath = [[NSBundle mainBundle] pathForResource:[vipUser valueForKey:@"gender"] ofType:@"png"];
                    _sexImgV.image = [UIImage imageWithContentsOfFile:sexpath];
                    [bottomView addSubview:_sexImgV];
                    [_sexImgV release];
                    
                    UILabel *ageLabel = [[UILabel alloc] init];
                    ageLabel.font = [UIFont boldSystemFontOfSize:13];
                    ageLabel.frame = CGRectMake(50, 0, 35, 15);
                    ageLabel.textAlignment = kTextAlignmentLeft;
                    ageLabel.text = [vipUser valueForKey:@"oldyears"];
                    ageLabel.textColor = [UIColor whiteColor];
                    ageLabel.backgroundColor = [UIColor clearColor];
                    [bottomView addSubview:ageLabel];
                    [ageLabel release];
                    
                    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 65, 15)];
                    topView.backgroundColor = [UIColor colorWithWhite:0.6 alpha:0.8];
                    [btn addSubview:topView];
                    [topView release];
                    
                    UILabel *nameLabel = [[UILabel alloc] init];
                    nameLabel.font = [UIFont boldSystemFontOfSize:13];
                    nameLabel.frame = CGRectMake(0, 0, 65, 15);
                    nameLabel.text = [vipUser valueForKey:@"pname"];
                    nameLabel.textAlignment = kTextAlignmentCenter;
                    nameLabel.textColor = [UIColor whiteColor];
                    nameLabel.backgroundColor = [UIColor clearColor];
                    [topView addSubview:nameLabel];
                    [nameLabel release];
                    
                    
                    UIImageView *_vipImageView = [[UIImageView alloc] initWithFrame:CGRectMake(2, 3, 15, 10)];
                    NSString *verifypath = [[NSBundle mainBundle] pathForResource:@"verify_card" ofType:@"png"];
                  
                    _vipImageView.image = [UIImage imageWithContentsOfFile:verifypath];
                    
                    [bottomView addSubview:_vipImageView];
                    [_vipImageView release];
                    
                }
            }
        }
    }
}
-(void)dealloc
{
    [super dealloc];
    [AppComManager cancalHandlesForObject:self];
}
@end
